package coder.common;

import coder.exception.NoHandlerFoundException;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.javassist.NotFoundException;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class MyErrorController implements ErrorController {

    /**
     * 处理错误请求的方法
     * 当访问的资源不存在时，此方法将被调用
     *
     * @throws NoHandlerFoundException 抛出NoHandlerFoundException异常，提示访问资源不存在
     */
    @RequestMapping("/error")
    public void error() {
        throw new NoHandlerFoundException("访问资源不存在");
    }
    @Override
    public String getErrorPath() {
        return "/error";
    }
}
